package cn.tedu.zhxy.controller;


import cn.tedu.zhxy.entity.Clazz;
import cn.tedu.zhxy.service.ClazzService;
import cn.tedu.zhxy.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-07-20
 */
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping("getClazzs")
    public Result getClazzs(){
        List<Clazz> list = clazzService.list();
        return Result.ok(list);
    }


    @GetMapping("/getClazzsByOpr/{page}/{limit}")
    public Result  getClazzsByOpr(@PathVariable  Long  page, @PathVariable Long limit,Clazz  clazz ){
        Page<Clazz>  pageParam = new Page<>(page,limit);
        IPage<Clazz> list  = clazzService.selectClazz(pageParam,clazz);
        System.out.println(list);
        return Result.ok(list);
    }
    @DeleteMapping("deleteClazz")
    public  Result  deleteClazz(@RequestBody List<Integer> ids){
        clazzService.removeByIds(ids);
        return Result.ok();
    }
    @PostMapping("saveOrUpdateClazz")
    public  Result  saveOrUpdateClazz(@RequestBody Clazz  clazz){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }



}

